<?php

/*

Fountain of Health (heal_pets.pro.php)

*/
ob_start();
$rank_checking = 1;
include "global.inc.php";

// Start checking

$checking = "heal_pets";
$limit1 = 1800;
$timeLimit = "half hour";
if ($getInfo[premium] == 1) { $limit1 = 900; $timeLimit = "15 minutes"; }
$limit = $timestamp - $limit1;

$findchecking = fetch("SELECT * FROM checking2 WHERE userid = '$userid' AND check_what = '$checking' AND timestamp > '$limit' AND game = '$game'");

if ($findchecking[id])
{
	die("$openHTML<p>You can only drink the water from the fountain every $timeLimit. Please come back later. <a href=$base_url/heal_pets.php?game=$game>Back</a></p>$closeHTML");
}

if (!$findchecking[id])
{
	mysql_query("DELETE FROM checking2 WHERE userid = '$userid' AND check_what = '$checking' AND game = '$game'");
	mysql_query("INSERT INTO checking2 (userid,check_what,timestamp,game) VALUES ('$userid','$checking','$timestamp','$game')");
}

// End checking

$checkStatus = fetch("SELECT * FROM one_player_battles2 WHERE userid = '$userid' AND game = '$game'");
if ($checkStatus[id])
{
	die(header(error("heal_pets.php?game=$game","You cannot use this while you're in a battle.")));
}

$randHeal = rand(1,5);
if ($randHeal <= "4")
{
	$healRandHP = rand(40,150);
	mysql_query("UPDATE user_pets2 SET current_hp = current_hp + $healRandHP WHERE owner = '$userid' AND adoption = '0'");

	mysql_query("UPDATE user_pets2 SET current_hp = max_hp WHERE owner = '$userid' AND adoption = '0' AND current_hp > current_hp");

	$error = "All of your pets have been healed $healRandHP points!";
}
if ($randHeal == 5)
{

	mysql_query("UPDATE user_pets2 SET current_hp = max_hp WHERE owner = '$userid' AND adoption = '0' AND game = '$game'");

	$error = "All of your pets have been fully healed!";
}

header(error("heal_pets.php?game=$game", "$error"));

?>